package edu.luas.digitalmedia.controller;

import edu.luas.digitalmedia.pojo.MyAddress;
import edu.luas.digitalmedia.service.MyAddressService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/address/list")
public class MyAddressListController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1：设置请求编码
        req.setCharacterEncoding("UTF-8");
        //2：设置响应编码
        resp.setContentType("text/html;charset=UTF-8");
        //3:调用业务层
        MyAddressService service = new MyAddressService();
        List<MyAddress> list = null;
        try {
            list = service.selectList();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        //4:将数据存储到request域
        req.setAttribute("models",list);
        //5:转发
        req.getRequestDispatcher("/list.jsp").forward(req,resp);
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }


}
